<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务，帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件，不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);

namespace app\api\controller;

use think\response\Json;
// use app\api\model\IndexBanner as IndexBannerModel;
// use app\api\model\IndexType as IndexTypeModel;
use app\api\service\Collect as CollectService;

use cores\exception\BaseException;
use app\store\model\User as UserModel;

/**
 * 收藏管理
 * Class User
 * @package app\api
 */
class Collect extends Controller
{

      /**
     * 点击收藏/取消商品
     * * @param int $goodsId 商品ID
     * @param int|null $type 收藏类型 1 收藏 , 0 取消
     * @return Json
     * @throws \cores\exception\BaseException
     */
    public function setCollect(int $goodsId, int $type): Json
    { 
       $params = array('goodsId'=>$goodsId,'type'=>$type);
        $CollectService = new CollectService;
        if (!$CollectService->setCollectList($params)) {
            return $this->renderSuccess($CollectService->getError() ?: '操作失败');
        }
        if($type == 1){
            return $this->renderSuccess('已成功收藏');
        }else{
            return $this->renderSuccess('已取消收藏');
        }
       
    }



    /**
     * 我的商品收藏
     * @return Json
     * @throws BaseException
     */
    public function getCollectList(): \think\response\Json
    {
        $CollectService = new CollectService;
        // 当前用户信息
        $CollectList = $CollectService->getCollectList($this->request->param());

        return $this->renderSuccess(compact('CollectList'));

    }


     /**
     * 验证该商品是否收藏过
     * @return Json
     * @throws BaseException
     */
    public function verifyCollect(int $goodsId): Json
    {
        $php_token = $this->request->header('Access-Token');
        $CollectService = new CollectService;
        $collectStatus = $CollectService->verifyCollect($goodsId,$php_token);
        
        return $this->renderSuccess(compact('collectStatus'));
    }

   
}
